<template>
  <div class="background">
    <div class="header">
      <img src="../assets/logo.jpg" alt="双体软件精英产业学院">
    </div>
    <div class="container">
      <div class="query-title"><b>我的评分历史</b></div>
      <div class="table-container">
        <table class="table" id="scoreTable">
          <thead>
            <tr>
              <th>姓名</th>
              <th>分数</th>
              <th>评分时间</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="score in scores" :key="score.recId">
              <td>选手{{ score.plaId }}</td>
              <td>{{ score.recScore }}</td>
              <td>{{ score.recDate ? score.recDate.slice(0, 19).replace('T', ' ') : '无日期' }}</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
    <footer class="footer">
      <div class="home-button1">
        <button class="home-button" @click="navigateTo('首页.html')"></button>
      </div>
      <div class="score-button1">
        <button class="score-button" @click="navigateTo('查看评分.html')"></button>
      </div>
      <div class="exit-button1">
        <button class="exit-button" @click="navigateTo('#')"></button>
      </div>
    </footer>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      scores: []
    };
  },
  methods: {
    async fetchScores() {
      try {
        const response = await axios.get('http://192.168.157.197:8083/api/record/list', {
          params: {
            judId: 1 // 固定评委 ID 为 1
          }
        });

        console.log(response.data); // 输出返回的数据，检查数据结构
        this.scores = response.data.data;
        this.scores.sort((a, b) => new Date(b.recDate) - new Date(a.recDate)); // 按评分时间降序排序
      } catch (error) {
        console.error('获取评分数据失败', error);
        alert('获取评分数据失败，请重试');
      }
    },
    navigateTo(url) {
      location.href = url;
    }
  },
  mounted() {
    this.fetchScores();
  }
};
</script>

<style>
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

.background {
  background-image: url('../assets/背景.jpg');
  background-size: cover;
  background-position: top center;
  background-attachment: fixed;
  height: 100%;
  position: relative;
}

.header {
  text-align: center;
  position: relative;
  z-index: 1;
}

.header img {
  width: 400px;
  max-width: 60%;
  margin-top: 10px;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.query-title {
  margin-bottom: 20px;
  font-size: 30px;
  text-align: center;
  color: rgba(104, 75, 52);
}

.table-container {
  width: 100%;
  max-height: 600px;
  overflow-y: auto;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  background-color: rgba(255, 255, 255, 0.8);
  position: relative;
}

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

.table th {
  padding: 10px;
  text-align: center;
  border-bottom: 1px solid #ddd;
  background: none;
}

.table tr {
  color: black;
}

.table td {
  padding: 10px;
  text-align: center;
  border-bottom: 1px solid #ddd;
}

.table tbody tr {
  background: linear-gradient(to right, #ffffff, rgb(255, 240, 228));
}

.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: #fff;
  text-align: center;
  padding: 8px 0 0 0;
  background-color: rgb(254, 251, 236);
  box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
  z-index: 2;
  display: flex;
  justify-content: space-around;
  margin-top: 20px;
}

.home-button,
.score-button {
  width: 40px;
  height: 40px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  border: none;
  cursor: pointer;
  outline: none;
  margin-top: 5px;
  background-color: transparent;
  z-index: 3;
}

.exit-button {
  width: 60px;
  height: 60px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  border: none;
  cursor: pointer;
  outline: none;
  margin-top: -8px;
  margin-right: -6px;
  background-color: transparent;
  z-index: 3;
}

.home-button1,
.score-button1,
.exit-button1 {
  width: 80px;
  height: 50px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  border: none;
  cursor: pointer;
  outline: none;
  margin: 0 auto;
  background-color: transparent;
}

.home-button {
  background-image: url('../assets/首页.jpg');
}

.score-button {
  background-image: url('../assets/查看评分.jpg');
}

.exit-button {
  background-image: url('../assets/退出.jpg');
}

.home-button1 {
  background-image: url('../assets/浅色.jpg');
}

.score-button1 {
  background-image: url('../assets/深色.jpg');
}

.exit-button1 {
  background-image: url('../assets/浅色.jpg');
}
</style>